using System;

namespace SortDemo
{
    public class Demo
    {
        public static void BubbleSort(int[] array)
        {
            if (array == null || array.Length <= 1)
                return;

            for (int i = 0; i < array.Length - 1; i++)
            {
                for (int j = 0; j < array.Length - 1 - i; j++)
                {
                    if (array[j] > array[j + 1])
                    {
                        int temp = array[j];
                        array[j] = array[j + 1];
                        array[j + 1] = temp;
                    }
                }
            }
        }

        public static void Main()
        {
            int[] numbers = { 5, 2, 9, 1, 5, 6 };
            
            Console.WriteLine("排序前的数组：");
            foreach (int num in numbers)
                Console.Write(num + " ");

            BubbleSort(numbers);

            Console.WriteLine("\n排序后的数组：");
            foreach (int num in numbers)
                Console.Write(num + " ");
        }
    }
}